<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

  
  <title>glog入门 | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="参考：https:&#x2F;&#x2F;github.com&#x2F;google&#x2F;glog 的Build from Source 构建glogmkdir test_glog &amp;&amp; cd test_glog vim WORKSPACE 123456789101112131415load(&quot;@bazel_tools&#x2F;&#x2F;tools&#x2F;build_defs&#x2F;repo:http.bzl&quot;, &amp;qu">
<meta property="og:type" content="article">
<meta property="og:title" content="glog入门">
<meta property="og:url" content="http://cui-rongpei.gitee.io/blog/2022/09/25/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/%E4%BD%BF%E7%94%A8C++%E7%BC%96%E5%86%99%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E6%A1%86%E6%9E%B6/glog%E5%85%A5%E9%97%A8/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="参考：https:&#x2F;&#x2F;github.com&#x2F;google&#x2F;glog 的Build from Source 构建glogmkdir test_glog &amp;&amp; cd test_glog vim WORKSPACE 123456789101112131415load(&quot;@bazel_tools&#x2F;&#x2F;tools&#x2F;build_defs&#x2F;repo:http.bzl&quot;, &amp;qu">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2022-09-25T08:17:42.738Z">
<meta property="article:modified_time" content="2022-09-25T08:56:58.107Z">
<meta property="article:author" content="John Doe">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/blog/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  
<link rel="stylesheet" href="/blog/css/style.css">

<meta name="generator" content="Hexo 5.4.2"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/blog/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/blog/">Home</a>
        
          <a class="main-nav-link" href="/blog/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/blog/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://cui-rongpei.gitee.io/blog"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-深度学习/使用C++编写深度学习框架/glog入门" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/blog/2022/09/25/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/%E4%BD%BF%E7%94%A8C++%E7%BC%96%E5%86%99%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E6%A1%86%E6%9E%B6/glog%E5%85%A5%E9%97%A8/" class="article-date">
  <time datetime="2022-09-25T08:17:42.738Z" itemprop="datePublished">2022-09-25</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/blog/categories/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/">深度学习</a>►<a class="article-category-link" href="/blog/categories/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/%E4%BD%BF%E7%94%A8C-%E7%BC%96%E5%86%99%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E6%A1%86%E6%9E%B6/">使用C++编写深度学习框架</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      glog入门
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>参考：<a target="_blank" rel="noopener" href="https://github.com/google/glog">https://github.com/google/glog</a> 的Build from Source</p>
<h1 id="构建glog"><a href="#构建glog" class="headerlink" title="构建glog"></a>构建glog</h1><p>mkdir test_glog &amp;&amp; cd test_glog</p>
<p>vim WORKSPACE</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">load(&quot;@bazel_tools//tools/build_defs/repo:http.bzl&quot;, &quot;http_archive&quot;)</span><br><span class="line"></span><br><span class="line">http_archive(</span><br><span class="line">    name = &quot;com_github_gflags_gflags&quot;,</span><br><span class="line">    sha256 = &quot;34af2f15cf7367513b352bdcd2493ab14ce43692d2dcd9dfc499492966c64dcf&quot;,</span><br><span class="line">    strip_prefix = &quot;gflags-2.2.2&quot;,</span><br><span class="line">    urls = [&quot;https://github.com/gflags/gflags/archive/v2.2.2.tar.gz&quot;],</span><br><span class="line">)</span><br><span class="line"></span><br><span class="line">http_archive(</span><br><span class="line">    name = &quot;com_github_google_glog&quot;,</span><br><span class="line">    sha256 = &quot;122fb6b712808ef43fbf80f75c52a21c9760683dae470154f02bddfc61135022&quot;,</span><br><span class="line">    strip_prefix = &quot;glog-0.6.0&quot;,</span><br><span class="line">    urls = [&quot;https://github.com/google/glog/archive/v0.6.0.zip&quot;],</span><br><span class="line">)</span><br></pre></td></tr></table></figure>

<p>vim build</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">cc_binary(</span><br><span class="line">    name = &quot;main&quot;,</span><br><span class="line">    srcs = [&quot;main.cc&quot;],</span><br><span class="line">    deps = [&quot;@com_github_google_glog//:glog&quot;],</span><br><span class="line">)</span><br></pre></td></tr></table></figure>

<p>vim main.cc</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">#include&lt;iostream&gt;</span><br><span class="line">int main()&#123;&#125;</span><br></pre></td></tr></table></figure>

<p>Building from Source</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">bazel build //:main</span><br></pre></td></tr></table></figure>

<h1 id="Getting-Start"><a href="#Getting-Start" class="headerlink" title="Getting Start!"></a>Getting Start!</h1><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">#include&lt;iostream&gt;</span><br><span class="line">#include&lt;glog/logging.h&gt;   //头文件</span><br><span class="line">int main(int argc, char * argv[])&#123;</span><br><span class="line">	google::InitGoogleLogging(argv[0]); //初始化</span><br><span class="line">	LOG(ERROR) &lt;&lt; &quot;hello world!&quot;;</span><br><span class="line">	google::ShutdownGoogleLogging();   //销毁</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>几个比较重要的宏</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">FLAGS_logtostderr = true;//设置日志消息是否转到标准输出而不是日志文件</span><br><span class="line">FLAGS_alsologtostderr = true;//设置日志消息除了日志文件之外是否输出到标准输出</span><br><span class="line">FLAGS_colorlogtostderr = true;//设置日志消息颜色</span><br><span class="line">FLAGS_log_prefix = true;//设置日志前缀是否应该添加到每行输出</span><br><span class="line">FLAGS_logbufsecs = 0;//设置可以缓冲日志的最大秒数，0指实时输出</span><br><span class="line">FLAGS_max_log_size = 10;//设置最大日志文件大小（以MB为单位），超过会对文件进行分割</span><br><span class="line">FLAGS_stop_logging_if_full_disk = true;//设置是否在磁盘已满时避免日志记录到磁盘</span><br><span class="line">FLAGS_minloglevel = google::GLOG_WARNING;//设置最小处理日志的级别</span><br></pre></td></tr></table></figure>


      
    </div>
    <footer class="article-footer">
      <a data-url="http://cui-rongpei.gitee.io/blog/2022/09/25/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/%E4%BD%BF%E7%94%A8C++%E7%BC%96%E5%86%99%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E6%A1%86%E6%9E%B6/glog%E5%85%A5%E9%97%A8/" data-id="cl8h5o797000esot9gjfuc49a" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/blog/2022/09/25/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/%E4%BD%BF%E7%94%A8C++%E7%BC%96%E5%86%99%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E6%A1%86%E6%9E%B6/gflags%E5%85%A5%E9%97%A8/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          gflags入门
        
      </div>
    </a>
  
  
    <a href="/blog/2022/09/25/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/%E4%BD%BF%E7%94%A8C++%E7%BC%96%E5%86%99%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E6%A1%86%E6%9E%B6/bazel%E5%85%A5%E9%97%A8/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">bazel入门</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/C-C/">C/C++</a></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/">深度学习</a><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/%E4%B8%9C%E6%96%B9%E8%80%80%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/">东方耀机器学习</a></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/%E4%BD%BF%E7%94%A8C-%E7%BC%96%E5%86%99%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E6%A1%86%E6%9E%B6/">使用C++编写深度学习框架</a></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/">深度学习环境搭建</a></li></ul></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E8%AE%BA%E6%96%87%E7%AC%94%E8%AE%B0/">论文笔记</a></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E8%BF%91%E6%9C%9F%E8%A7%84%E5%88%92/">近期规划</a></li></ul>
    </div>
  </div>


  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2022/09/">September 2022</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/blog/2022/09/25/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/%E4%BD%BF%E7%94%A8C++%E7%BC%96%E5%86%99%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E6%A1%86%E6%9E%B6/gflags%E5%85%A5%E9%97%A8/">gflags入门</a>
          </li>
        
          <li>
            <a href="/blog/2022/09/25/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/%E4%BD%BF%E7%94%A8C++%E7%BC%96%E5%86%99%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E6%A1%86%E6%9E%B6/glog%E5%85%A5%E9%97%A8/">glog入门</a>
          </li>
        
          <li>
            <a href="/blog/2022/09/25/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/%E4%BD%BF%E7%94%A8C++%E7%BC%96%E5%86%99%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E6%A1%86%E6%9E%B6/bazel%E5%85%A5%E9%97%A8/">bazel入门</a>
          </li>
        
          <li>
            <a href="/blog/2022/09/24/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/%E4%BD%BF%E7%94%A8C++%E7%BC%96%E5%86%99%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E6%A1%86%E6%9E%B6/%E4%BD%BF%E7%94%A8C++%E7%BC%96%E5%86%99%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E6%A1%86%E6%9E%B6/">前言 环境准备</a>
          </li>
        
          <li>
            <a href="/blog/2022/09/24/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/%E8%B6%85%E7%AE%97%E5%B9%B3%E5%8F%B0%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/">超算平台深度学习环境搭建</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2022 John Doe<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/blog/" class="mobile-nav-link">Home</a>
  
    <a href="/blog/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  
<link rel="stylesheet" href="/blog/fancybox/jquery.fancybox.css">

  
<script src="/blog/fancybox/jquery.fancybox.pack.js"></script>




<script src="/blog/js/script.js"></script>




  </div>
</body>
</html>